<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use yii\bootstrap\ActiveForm;
use kartik\editable\Editable;

$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Finances'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
$orders = $model->order;
?>
<style type="text/css">
	.widget-box  {border: 1px solid #CCC; color: #393939;}
	.widget-box .widget-header {color: #FFF;background:#333;padding:15px 0px;text-align:center;}
	.widget-box  .color2 {background:#b34e93;}
	.widget-box .widget-body {padding:5px 15px;margin-top:15px;font-size: 13px;font-family: 'Open Sans','Microsoft Yahei';line-height:1.8}
	.widget-box .widget-body .price {text-align: center;font-size: 16px;font-weight:bold;color:#000;}
</style>
<?=  yii\web\View::registerCssFile("/css/colorbox.css" ,['depends' => 'app\assets\AppAsset']) ?>
<?=  yii\web\View::registerJsFile("/js/jquery.colorbox-min.js" ,['depends' => 'app\assets\AppAsset']) ?>

<div class="finance-view">
    
	<div class="">
		<div class="col-xs-6 col-sm-4 pricing-box">
			<div class="widget-box">
				<div class="widget-header"><?= Yii::$app->params['finance_type'][$model->type] ?></div>
				<div class="widget-body">
					<div class="widget-main">
						<ul class="list-unstyled"><li>收(付)款人 : <?= $model->name ?></li></ul>
						<ul class="list-unstyled"><li>收(付)款单位 : <?= $model->company ?></li></ul>
						<ul class="list-unstyled"><li>付(付)款方式 : <?= Yii::$app->params['finance_price_type'][$model->price_type] ?> </li></ul>
						<ul class="list-unstyled"><li>收(付)款账号 : <?= $model->account ?></li></ul>
						<ul class="list-unstyled"><li>备注 : 
							<?php 
							if($model->user_id == \yii::$app->user->id){
							    echo  Editable::widget([
					               'name' => 'Finance[desc]',
					              'value' => $model->desc,
					                'asPopover' => true,
					                'header' => Yii::t('app.finance', 'Desc'),
					              'inputType' => Editable::INPUT_TEXTAREA,
					                'size'=>'md',
					                'formOptions' => ['action'=>'/finance/finance/edit?id='.$model->id, 'method'=>'get'],
					                'options' => ['class'=>'form-control', 'placeholder'=> Yii::t('app.finance', 'Desc')],
					              ]);
							 }else{
							 	 echo $model->desc;
							 }
					        ?>
          				</li></ul>
						<ul class="list-unstyled"><li>状态 : <?= Yii::$app->params['finance_status'][$model->status] ?></li></ul>
						<hr style="margin-bottom:10px;">
						<div class="price" style="color: #ea656a;">
							总金额 :
 							<?= Yii::$app->formatter->asCurrency($model->orderPrice) ?>
						</div>
					</div>
				</div>
			</div>
		</div>

    
		<div class="col-xs-6 col-sm-4">
			<div class="widget-box">
				<div class="widget-header color2">相关订单</div>
				<div class="widget-body">
					<div class="widget-main">
						<?php if(!empty($orders)) { ?>
							<!-- 关联订单 -->
							<?php foreach($orders as $order){ ?>
								<ul class="list-unstyled">
									<a style="display:inline-block;width:100%;" href="/order/order/view?id=<?= $order->order_id?>" target="_blank" ><?= $order->order->code ?></a>
									<font style="display:inline-block;width:30%;"><?= $order->order->username ?></font>
									<font style="display:inline-block;width:32%;"><?= $order->order->phone ?></font>
									<font style="display:inline-block;width:35%;color:#ea656a;font-weight:bold;">
										<?= Yii::$app->formatter->asCurrency($order->price) ?>
									</font>
								</ul>
								<hr>
							<?php } ?>
						<?php } ?>
					</div>
				</div>
			</div>
		</div>


		<!-- 审核界面 -->
		<div class="col-xs-6 col-sm-4">
			<?php
				$r = '';	// 用户角色
				$roles = Yii::$app->authManager->getRolesByUser(Yii::$app->user->id);
				foreach($roles as $role){
					$r = $role->name;
				}
			?>

			<?php
				if($model->type == 1){ //	收款
					echo $this->render('status1', ['model' => $model, 'role'=>$r]);
				}
			?>

			<?php
				if($model->type == 2){ // 应收账款
					echo $this->render('status2', ['model' => $model, 'role'=>$r]);
				}
			?>
				
			<?php
				if($model->type == 3){ // 退款 
					echo $this->render('status3', ['model' => $model, 'role'=>$r]);
				}
			?>
		</div>

	</div><!-- container -->

</div>



<div class="col-md-12 thumbnails" style="margin-top:30px;">
	<h2 class="page-header"><small>审批参考资料</small></h2>
<?php 
	if($model->allImg){
		foreach($model->allImg as $img){
			echo  '<a data-rel="colorbox" class="cboxElement" href="/'. $img->img .'" >';
			echo  \yii\helpers\Html::img('/'.$img->img, ['width'=>150, 'style'=>'margin-right:10px;']);
			echo '</a>';
		}
	}
?>
</div>

<!--发票审批-->
<?=$this->render('check-invoice', ['model' => $model, 'role'=>$r]);?>


<?php app\components\JsBlock::begin() ?>
<script>
	var colorbox_params = {
		 rel: 'colorbox',
		 scrolling:false,
		 close:'&times;',
		 maxWidth:'100%',
		 maxHeight:'100%',
		 onOpen:function(){
			 $overflow = document.body.style.overflow;
			 document.body.style.overflow = 'hidden';
		 },
		 onClosed:function(){
			 document.body.style.overflow = $overflow;
		 },
		 onComplete:function(){
		   $.colorbox.resize();
		 }
	};

    $('.thumbnails [data-rel="colorbox"]').colorbox(colorbox_params);
</script>
<?php app\components\JsBlock::end() ?>

